var local="http://47.104.10.151";
// 47.104.10.151
var keyId=getCookie('userId');




function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}
//通过鼠标点击事件创建HTTP请求
function onClickAjax_message123() {
    var xmlHttp12 = createXMLHttp_message12();

    function createXMLHttp_message12() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;
    }

    var name = document.getElementById("name").value;
    var mobile =document.getElementById("mobile").value;
    var email = document.getElementById("email").value;

    var company_name1111 = document.getElementById("company_name").value;
    var company_address = document.getElementById("company_address").value;
    var company_mobile=document.getElementById("company_mobile").value;
    var company_kaihuhang=document.getElementById("company_kaihuhang").value;
    var conpany_code = document.getElementById("conpany_code").value;
    var company_tax_code=document.getElementById("company_tax_code").value;
    var txt1 = "keyId=" + keyId + "&user_name=" + name + "&mobile=" + mobile + "&email=" + email + "&company_name=" + company_name1111  +"&company_address=" + company_address + "&company_mobile=" + company_mobile +"&company_kaihuhang=" + company_kaihuhang + "&company_code=" + conpany_code + "&company_tax_code=" + company_tax_code;
    var url = local+":8080/login/ModifyUser";//服务器URL
    xmlHttp12.open("POST", url, true);
    xmlHttp12.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp12.send(txt1);
    //传输结束
    alert("保存成功");
}



function getCompany_code() {
    var xmlHttp = createXMLHttpCompany_code();
    var txt = "";//用于存储拼接字符串；
    var url=local+":8080/login/displayCompany_Code";
    //拼接字符
    txt = "user_Id=" + keyId;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);


    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {

            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");


            var company_code= json.msg;
            document.getElementById("company_code1").value=company_code;
        }

    };


    function createXMLHttpCompany_code() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;
    }

}

function getInvitecode() {
    var xmlHttp = createXMLHttpInvite_code();
    var txt = "";//用于存储拼接字符串；
    var url=local+":8080/login/displayInvite_Code";
    //拼接字符
    txt = "user_Id=" + keyId;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {

            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");
            var invite_code= json.msg;
            document.getElementById("invite_code").value=invite_code;
        }
    };
    function createXMLHttpInvite_code() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;
    }
}

function rePassword() {
    var xmlHttp = createXMLHttprePassWord();
    var txt = "";//用于存储拼接字符串；
    var url=local+":8080/login/resetPassWord";
    //拼接字符
    var password=document.getElementById('newpass')
    txt = "password="+password+"&user_Id=" + keyId;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("您已成功修改密码！");


    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {

            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");
            var invite_code= json.msg;
            document.getElementById("invite_code").value=invite_code;
        }
    };
    function createXMLHttprePassWord() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;
    }
}

function getUserInfo() {
    var xmlHttp1 = createXMLHttp2();
    var url=local+":8080/login/finduserById";
    //拼接字符
    var txt = "user_Id="+keyId;
    xmlHttp1.open("POST", url, true);
    xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp1.send(txt);

    xmlHttp1.onreadystatechange = function () {
        if (xmlHttp1.readyState == 4 && xmlHttp1.status == 200) {

            var result = xmlHttp1.responseText;
            var json = eval("(" + result + ")");
            document.getElementById("company_name").value=json.data.company_name;
            document.getElementById("company_address").value=json.data.company_address;
            document.getElementById("company_mobile").value=json.data.company_mobile;
            document.getElementById("company_kaihuhang").value=json.data.company_kaihuhang;
            document.getElementById("conpany_code").value=json.data.company_code;
            document.getElementById("company_tax_code").value=json.data.company_tax_code;
            var name=json.data.user_name;
            if(name==null){
                document.getElementById("name").value='未填写' ;
            }else{
                document.getElementById("name").value=name ;
            }
            var mobile=json.data.mobile;
            if(mobile==null){
                document.getElementById("mobile").value='未填写' ;
            }else{
                document.getElementById("mobile").value=mobile;
            }
            var email =json.data.email;
            if(email==null){
                document.getElementById("email").value='未填写' ;
            }else{
                document.getElementById("email").value=email ;
            }
            var invite_code=json.data.invite_code;
            if(invite_code==null){
                document.getElementById("invite_code").value='未填写' ;
            }else{
                document.getElementById("invite_code").value=invite_code ;
            }
        }
    };

    function createXMLHttp2() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;
    }
}


$( document ).ready(function() {

    getUserInfo();
    getCompany_code();
    getInvitecode();

});